<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 

<fmt:setBundle basename="ApplicationMessage" />
<fmt:setLocale value="zh_CN" />

<sec:authentication property="principal" var="currentPrincipal" scope="page" />

<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <%@ include file="/WEB-INF/include/meta.jsp"%>
  <%@ include file="/WEB-INF/include/css.jsp"%>
</head>

<body>
  <%@ include file="/WEB-INF/include/header.jsp"%>
  <%@ include file="/WEB-INF/include/menu.jsp"%>

  <div class="container main-content">
    <div class="panel panel-default x-panel x-panel-layout">
      <div class="panel-heading">
        <ol class="breadcrumb">
          <li><a href="${ctx.host}/user">用户管理</a></li>
          <li class="active">满意度调查</li>
        </ol>
      </div>

      <div class="panel-body">
        <div class="col-xs-2 x-panel-layout-left no-horizontal-padding">
          <%@ include file="/WEB-INF/include/submenu.jsp"%>
        </div>

        <div class="col-xs-10 x-panel-layout-right">
          <form id="inbody-report-form" class="form-horizontal" method="GET" action="${ctx.host}/gift-coupons/search" data-validate="true">
            <div class="x-breadcrumb-wrapper">
              <div class="x-breadcrumb clearfix">
                <h2><i class="glyphicon glyphicon-fire"></i>&nbsp;&nbsp;<span>满意度调查&nbsp;-&nbsp;礼品券核销</span></h2>
              </div>
            </div>
            
            <div class="x-toolbar-wrapper top-margin-20 clearfix">
              <div class="btn-group pull-right">
                <a href="${ctx.host}/gift-coupons/export-view" data-target="#export" data-toggle="modal" class="btn btn-default x-btn btn-shadow btn-shadow-default">
                  <i class="glyphicon glyphicon-floppy-save"></i>&nbsp;&nbsp;导出
                </a>
              </div>
            </div>

            <div class="x-breadcrumb-wrapper top-margin-20" style="position: relative;">
              <div class="form-group x-form-group">
                <label class="col-xs-2 control-label">礼品券券码</label>
                <div class="col-xs-3" style="width: 30%;">
                  <input class="form-control" name="code" placeholder="请输入完整的礼品券券码" data-validate="required" value="${code}">
                </div>
              </div>
              
              <div class="x-breadcrumb-wrapper clearfix" style="position: relative; margin-top: 15px;">
                <div class="btn-group pull-right">
                  <button id="search_btn" type="submit" class="btn btn-success btn-shadow btn-shadow-success x-btn">查询</button>&nbsp;&nbsp;&nbsp;&nbsp;
                </div>
              </div>
            </div>
          </form>

          <c:if test="${search}">
            <div style="margin-top: 20px;">
              <table data-toggle="table" class="table table-striped table-hover">
                <thead>
                  <tr>
                    <th class="text-center">门店</th>
                    <th class="text-center">姓名</th>
                    <th class="text-center">手机号</th>
                    <th class="text-center">开始日期</th>
                    <th class="text-center">截至日期</th>
                    <th class="text-center">状态</th>
                    <th class="text-center">核销时间</th>
                    <th class="text-center">兑换礼物</th>
                    <th class="text-center">操作</th>
                  </tr>
                </thead>
                <tbody>
                  <c:choose>
                    <c:when test="${empty surveys}">
                      <tr><td colspan="9" style="text-align:center;">不存在券码为${code}的礼品券</td></tr>
                    </c:when>
                    <c:otherwise>
                      <c:forEach var="survey" items="${surveys}">
	                    <tr>
                          <td class="text-center">${survey.courseRound.site.name}</td>
	                      <td class="text-center">${survey.courseRound.student.name}</td>
                          <td class="text-center">${survey.courseRound.student.mobile}</td>
                          <td class="text-center"><fmt:formatDate value="${survey.coupon.effectiveStartDate}" pattern="yyyy-MM-dd"/></td>
	                      <td class="text-center"><fmt:formatDate value="${survey.coupon.effectiveEndDate}" pattern="yyyy-MM-dd"/></td>
	                      <td class="text-center">${survey.coupon.status.description}</td>
                        <td class="text-center"><fmt:formatDate value="${survey.coupon.useTime}" pattern="yyyy-MM-dd"/></td>
                        <td class="text-center">${survey.gift}</td>
	                      <td class="text-center">
                             <c:if test="${survey.coupon.status.isClaimed()}">
                               <a href="${ctx.host}/gift-coupons/${survey.coupon.id}/use" data-target="#use" data-toggle="modal">核销</a>
                             </c:if>
	                      </td>
	                    </tr>
	                  </c:forEach>
                    </c:otherwise>
                  </c:choose>
                </tbody>
              </table>
            </div>
          </c:if>
          
        </div>
      </div>
    </div>
  </div>

  <%@ include file="/WEB-INF/include/script.jsp"%>

  <d:resource root="${ctx.resource}/build" type="script" src="js/page/market/gift-coupon.js">
    <script type="text/javascript">
      require(['page/market/gift-coupon'],function(page){
        page.init();
      })
    </script>
  </d:resource>
</body>
</html>